package com.my.hzb.user.ctrl;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;

import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.my.hzb.common.bean.ResultBean;
import com.my.hzb.entiy.UserMessage;
import com.my.hzb.user.service.UserMessageService;

@Controller
@RequestMapping("/userMsg")
public class UserMessageCtrl {

	private static final Logger log = LogManager.getLogger(UserMessageCtrl.class);
	@Autowired
	private UserMessageService userMessageService;
	
	@RequestMapping("/getMsgByName")
	@ResponseBody
	public ResultBean getMesByName(String userName){
		ResultBean result = new ResultBean(ResultBean.RETURN_ERROR_CODE,ResultBean.RETURN_ERROR_MSG);
		UserMessage msg = new UserMessage();
		msg.setUserName(userName);
		int count = userMessageService.count(msg);
		result.setReturnStr(count+"");
		result.setRespCode(ResultBean.RETURN_SUCCESS_CODE);
		result.setRespMsg("OK");
		return result;
	}
	@RequestMapping("/checkMsg")
	@ResponseBody
	public ResultBean checkMsg(Integer id){
		ResultBean result = new ResultBean(ResultBean.RETURN_ERROR_CODE,ResultBean.RETURN_ERROR_MSG);
		UserMessage msg = userMessageService.getOne(id);
		if(null!=msg){
			msg.setStatus(1);
			msg.setUpdateTime(new Date());
			
			userMessageService.update(msg);
			result.setRespCode(ResultBean.RETURN_SUCCESS_CODE);
			result.setRespMsg("OK");
		}
		return result;
	}
	
}
